collect (APP_COMMON_SOURCES helper.c)

set (_linker_script "${CMAKE_CURRENT_SOURCE_DIR}/linker_remote.ld")
set_property (GLOBAL PROPERTY APP_LINKER_OPT "-T\"${_linker_script}\"")
set (_linker_large_text_script "${CMAKE_CURRENT_SOURCE_DIR}/linker_large_text.ld")
set_property (GLOBAL PROPERTY APP_LINKER_LARGE_TEXT_OPT "-T\"${_linker_large_text_script}\"")

find_path(XIL_INCLUDE_DIR NAMES xparameters.h PATHS ${CMAKE_FIND_ROOT_PATH})
collect (PROJECT_INC_DIRS "${XIL_INCLUDE_DIR}")

find_library(LIBXIL_LIB NAMES xil PATHS ${CMAKE_FIND_ROOT_PATH})
get_filename_component(LIBXIL_LIB_DIR ${LIBXIL_LIB} DIRECTORY)
collect(PROJECT_LIB_DIRS ${LIBXIL_LIB_DIR})

# check PM API for certain headers and set client version based
# on which functions are found
find_path(VERSION_1_PM_CLIENT "pm_api_sys.h")
if (NOT VERSION_1_PM_CLIENT)
  # check for version 2
  find_path(VERSION_2_PM_CLIENT "xpm_client_api.h")
  if (NOT VERSION_2_PM_CLIENT)
    message(FATAL_ERROR "PM Client not found")
  else()
   collect (APP_EXTRA_C_FLAGS "  -DVERSION_2_PM_CLIENT ")
  endif()
else()
 collect (APP_EXTRA_C_FLAGS "  -DVERSION_1_PM_CLIENT ")
endif()

collect(PROJECT_LIB_DEPS xil)
collect(PROJECT_LIB_DEPS c)
collect(PROJECT_LIB_DEPS m)
find_library(XILMEM_LIB NAMES xilmem PATHS ${CMAKE_FIND_ROOT_PATH})
if(XILMEM_LIB)
  collect (PROJECT_LIB_DEPS xilmem)
endif(XILMEM_LIB)

if (VERSION_2_PM_CLIENT)
find_library(HAS_PM_LIB NAMES xillibpm PATHS ${CMAKE_FIND_ROOT_PATH})
collect (PROJECT_LIB_DEPS xillibpm)
else()
find_library(HAS_PM_LIB NAMES xilpm PATHS ${CMAKE_FIND_ROOT_PATH})
collect (PROJECT_LIB_DEPS xilpm)
endif(VERSION_2_PM_CLIENT)
